var vm = new Vue({
    el: "#main",
    data: {
        table: {
            tableHeight: 0,
            tableData: []
        },
        page: {
            current: 0,
            size: 10,
            total: 0,
        },
        bindFormData: {//绑定使用
            family: '',
            kpiItemId: '',
            ruleScope: ''
        },
        searchFormData: {//搜索使用
            family: '',
            kpiItemId: '',
            ruleScope: ''
        },
        searchData: {
            familyList: [],
            kpiItemList: [],
            categoryList: []
        },
        upload: {
            fileList: []
        },
        download: {
            downLoadStatus: false
        }
    },
    methods: {
        loadFormData: function () {
            VanyAjax("/kpi/rule/query/search/data", {}, "POST")
                .done(function (data) {
                    this.searchData = data
                }, false, this);
        },
        loadTableData: function () {
            var params = jsonUtil.mergeJsonObj(this.page, this.searchFormData);
            VanyAjax("/kpi/rule/query/page", params, "POST", "#kpiRule")
                .done(function (data) {
                    this.table.listLoading = false;
                    this.page.total = data.total;
                    this.table.tableData = data.records
                }, true, this);
        },
        loadSearchData: function () {
            //加载搜索数据
            this.searchFormData = jsonUtil.getValue(this.bindFormData);
            this.loadTableData();
        },
        downLoadTemplate() {
            window.location.href = "/kpi/rule/export/template";
        },
        exportExcel() {
            window.location.href = "/kpi/rule/export/data?"+jsonUtil.serialize(this.searchFormData);
        },
        submitUpload() {
            this.$refs.upload.submit();
        },
        handleOnSuccess(response, file, fileList) {
            console.log(response);
            if (response.code == "000000") {
                this.$message({showClose: true, message: '导入成功', type: 'success'});
            } else {
                this.$message({showClose: true, message: response.rspMsg, type: 'error'});
            }
            this.page.current = 1;
            this.loadTableData();
            this.upload.fileList = [];
        },
        handleSizeChange(size) {
            this.page.size = size;
            this.loadTableData();
        },
        handleCurrentChange(current) {
            this.page.current = current;
            this.loadTableData();
        }
    },
    mounted: function () {
        this.table.tableHeight = 500;
        this.loadFormData();
        this.loadTableData();
    }
})
